class Stack{
    constructor(){
        this.items = {};//放置元素
        this.count = 0; //元素的个数
    }

    //添加元素
    push(element){
        this.items[this.count] = element;
        this.count++;
    }

    //最后一个元素
    pop(){
        if(this.isEmpty()){
            return undefined;
        }
        let top = this.items[this.count-1];
        delete this.items[this.count-1];
        this.count--;
        return top
    }

    //peek  返回栈顶的元素
    peek(){
        return this.items[this.count-1]
    }

    //判断栈是否为空
    isEmpty(){
        return this.count === 0
    }

    //清空栈
    clear(){
        this.items = {};
        this.count = 0;
    }

    //获取栈内元素的个数
    size(){
        return this.count;
    }

    //转成字符串
    toString(){
        if(this.isEmpty()){
            return ''
        }
        let str = this.items[0];
       
        for(let i = 1;i<this.count;i++){
            str = `${str}${this.items[i]}`
        }
        return str
    }

    isHui(){
        let str1 = this.toString();

        let count = this.count;

        let str2 = '';

        for(let i = 0;i<count;i++){
            str2 += this.pop();
        }
        
        return str1 === str2
    }

}

// let obj = {};

// obj.xxx = xxx;

let s = new Stack();

//aba  aba

s.push('a');

s.push('b');

s.push('s');

console.log(s.toString());

console.log(s.isHui())
// // console.log(s.pop());

// console.log(s.toString());

// //十进制转二进制
// function decimalToBinary(number){
//     let s = new Stack();
//     let rem = ''; //余数
//     let str = '';
//     while(number > 0){
//         rem = Math.floor(number%2);
//         s.push(rem);
//         number = Math.floor(number/2);
//     }

//     let count = s.size();
//     for(let i = 0;i<count;i++){
//         str += `${s.pop()}`
//     }
//     return str
// }

// console.log(decimalToBinary(10))